package com.link.play.fit.ai.ui.main.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.link.play.fit.ai.ui.adjust.adjustPage.fragment.AdjustPageFragment1
import com.link.play.fit.ai.ui.adjust.adjustPage.fragment.AdjustPageFragment2
import com.link.play.fit.ai.ui.adjust.adjustPage.fragment.AdjustPageFragment3
import com.link.play.fit.ai.ui.adjust.adjustPage.fragment.AdjustPageFragment4
import com.link.play.fit.ai.ui.adjust.adjustPage.fragment.AdjustPageFragment5

class AdjustPageAdapter(
    fragmentManager: FragmentManager, lifecycle: Lifecycle
) : FragmentStateAdapter(fragmentManager, lifecycle) {

    private val fragmentClasses = arrayOf(
        AdjustPageFragment1::class.java,
        AdjustPageFragment2::class.java,
        AdjustPageFragment3::class.java,
        AdjustPageFragment4::class.java,
        AdjustPageFragment5::class.java,

    )


    override fun getItemCount(): Int = fragmentClasses.size

    override fun createFragment(position: Int): Fragment {
        val fragment: Class<*> = fragmentClasses[position]
        return try {
            (fragment.getDeclaredConstructor().newInstance() as Fragment)
        } catch (e: IllegalAccessException) {
            throw RuntimeException(e)
        } catch (e: InstantiationException) {
            throw RuntimeException(e)
        }
    }

}
